package priv.yiyuan.example.design;

/**
 * 文档类
 * <p>
 * 桥接模式(抽象部分)/模板方法模式(抽象类)
 */
public abstract class Document {

    protected DocumentFormatter formatter;

    public Document(DocumentFormatter formatter) {
        this.formatter = formatter;
    }

    public void setFormatter(DocumentFormatter formatter) {
        this.formatter = formatter;
    }

    public final void generate() {

        loadData();
        String formatContent = this.formatContent();
        this.saveDocument(formatContent);
        System.out.println("文档生成成功。");

    }

    protected void loadData() {
        System.out.println("加载文档数据...");
    }

    protected abstract String formatContent();

    protected void saveDocument(String content) {
        System.out.println("将内容保存至文档: " + content);
    }
}
